<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Service\UserService;
use Hyperf\HttpServer\Contract\RequestInterface;

class IndexController extends AbstractController
{
    private $userService;

    # [#Inject]
    public function __construct(UserService $userService)
    {
        $this->userService = $userService;
    }
    
    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }

    public function hello()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello  world {$user}.",
        ];
    }

    /**
     *
     *
     * @param RequestInterface $request
     * @return array
     */
    public function testRequest(RequestInterface $request)
    {
        $all = $request->all();
        return $all;
    }

    /**
     * 依赖注入
     *
     * @param RequestInterface $request
     * @return void
     */
    public function injectTest(RequestInterface $request)
    {
        return $this->userService->getInfoById($request->input('id'));
    }
}
